package com.wechat.config;

import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import com.wechat.annotation.Robot;

public class RobotBeanPostProcessor implements BeanPostProcessor {

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		Class<?> clazz = bean.getClass();
		if (AopUtils.isAopProxy(bean)) {
			clazz = AopUtils.getTargetClass(bean);
		}
		Robot robot = clazz.getAnnotation(Robot.class);
		if (robot != null) {
			RobotBean.New(robot, bean);
		}
		return bean;
	}
}
